import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/widgets.dart';

import '../controllers/fun_response1_controller.dart';

class FunResponse1View extends GetView<FunResponse1Controller> {
  const FunResponse1View({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print("FunResponse1View 展示UI");
    return Scaffold(
      appBar: getAppBar(context: context, title: "Obx()的方式"),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Obx(
              () {
                print("Obx count");
                return Text(
                  "count的值为: ${controller.count}",
                  style: TextStyle(color: Colors.red, fontSize: 30),
                );
              },
            ),
            Obx(
              () {
                print("Obx name");
                return Text(
                  "name的值为: ${controller.name}",
                  style: TextStyle(color: Colors.red, fontSize: 30),
                );
              },
            ),

            ElevatedButton(
              onPressed: () {
                controller.increment();
              },
              child: Text("加1"),
            ),

            ElevatedButton(
              onPressed: () {
                controller.changeName();
              },
              child: Text("改变名称"),
            ),
          ],
        ),
      ),
    );
  }
}
